<?php
	if (!session_start()) session_start();
	if (!isset($_SESSION['kiemtradangnhapthinguyet']) || $_SESSION['kiemtradangnhapthinguyet']!=1) {
		header('location: ../../../index.php');
		die();
	}
	$table = "users";
	$id = $_GET['id'];
	$kq=$qt->get_by_thutu($table,$id);
	$record=mysql_fetch_assoc($kq);
	if(isset($_POST['ok']))
	{
		$id=$_POST['id'];
		if($_POST['password']!='')
		{
			$field = array('password','hoten','dienthoai','diachi');
			
			$now = getdate();
			$ngay = $now["year"]."-".$now["mon"]."-".$now["mday"]." ".$now["hours"].":".$now["minutes"].":".$now["seconds"];
			
			 $values= array( format(md5($_POST["password"]),0),
			 format($_POST["hoten"],0),
			 format($_POST["dienthoai"],0),
			 format($_POST["diachi"],0));
			//echo $id;die;
			$res=$qt->updateObject($table,$field,$values,"id='$id'");
			
			if($res){
				echo "<script>alert('Sửa dữ liệu thành công !!!');history.go(-2);</script>";
			}
		}
			else{
				$field = array('hoten','dienthoai','diachi');
			
				$now = getdate();
				$ngay = $now["year"]."-".$now["mon"]."-".$now["mday"]." ".$now["hours"].":".$now["minutes"].":".$now["seconds"];
				
				 $values= array( format($_POST["hoten"],0),
				 format($_POST["dienthoai"],0),
				 format($_POST["diachi"],0));
				
				$res=$qt->updateObject($table,$field,$values,"id='$id'");
				if($res){
				echo "<script>alert('Sửa dữ liệu thành công !!!');history.go(-2);</script>";
				}
			}
	}

	
?>
            	<div class="dangnhap_title">
                <a href="index.php" style="color:#F8991D;" title="Trang chủ">Trang chủ</a>
                <span style="font-size:9px;">>></span> 
                Sản phẩm
                <span style="font-size:9px;">>></span> 
                <a href="index.php?p=<?php echo $table; ?>_quanly" style="color:#F8991D;">Users</a> 
            	</div>
            	<form method="post" action="index.php?p=<?php echo $table; ?>_sua">
                <input type="hidden" name="id" value="<?php echo $id; ?>" />
                <div class="dangnhap_col">
                    <div class="dangnhap_col_title" style="font-size:22px; color:#0E6BBB; width: 90%;">
                        Vietnamese's Information
                    </div>
                </div>
                <div class="dangnhap_col">
                    <div class="dangnhap_col_title">
                        &nbsp; &nbsp; &nbsp;- Email(*)
                    </div>
                    <div class="dangnhap_col_input">
                        <?php echo $record['email'];?>
                    </div>
                </div>
                <div class="dangnhap_col">
                    <div class="dangnhap_col_title">
                        &nbsp; &nbsp; &nbsp;- Password(*)
                    </div>
                    <div class="dangnhap_col_input">
                        <input type="password" name="password" id="password" style="width:520px; padding:0px;" />
                    </div>
                </div>
                <div class="dangnhap_col">
                    <div class="dangnhap_col_title">
                        &nbsp; &nbsp; &nbsp;- Họ tên
                    </div>
                    <div class="dangnhap_col_input">
                        <input type="text" name="hoten" id="hoten" style="width:520px; padding:0px;" value="<?php echo $record['hoten'];?>" />
                    </div>
                </div>
                <div class="dangnhap_col">
                    <div class="dangnhap_col_title">
                        &nbsp; &nbsp; &nbsp;- Địa chỉ
                    </div>
                    <div class="dangnhap_col_input">
                        <input type="text" name="diachi" id="diachi" style="width:520px; padding:0px;" value="<?php echo $record['diachi'];?>" />
                    </div>
                </div>
                <div class="dangnhap_col">
                    <div class="dangnhap_col_title">
                        &nbsp; &nbsp; &nbsp;- Điện thoại
                    </div>
                    <div class="dangnhap_col_input">
                        <input type="text" name="dienthoai" id="dienthoai" style="width:520px; padding:0px;" value="<?php echo $record['dienthoai'];?>" />
                    </div>
                </div>
                
                <div class="dangnhap_col">
                    <div class="dangnhap_col_input">
                        <input type="submit" class="ok" border="0" name="ok" id="ok" value="" />
                        <a href="javascript:history.go(-1);"><img src="imgs/exit_button.png" border="0" /></a>
                    </div>
                </div>
               	</form>